package com.ruoyi.wisdom.event;

import com.ruoyi.wisdom.constants.IotConstants;
import com.ruoyi.wisdom.domain.IotPickDeviceFace;
import com.ruoyi.wisdom.domain.swap.SwapPickFace;
import com.ruoyi.wisdom.service.IIotPickDeviceFaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class PickDeviceFaceEvent {

    @Autowired
    private IIotPickDeviceFaceService iotPickDeviceFaceService;

    /**
     * 添加|编辑
     *
     * @param iotDeviceFace
     */
    public void save(IotPickDeviceFace iotDeviceFace) {
        IotPickDeviceFace params = new IotPickDeviceFace();
        params.setUuid(iotDeviceFace.getUuid());
        params.setFacecode(iotDeviceFace.getFacecode());
        params.setDeviceNo(iotDeviceFace.getDeviceNo());
        IotPickDeviceFace result = iotPickDeviceFaceService.selectIotPickDeviceFace(params);
        iotDeviceFace.setStatus(IotConstants.FACE_STATUS_ADD);
        iotDeviceFace.setStatusOld(IotConstants.FACE_STATIC_OLD_ADD);
        if (result != null) {
            iotDeviceFace.setId(result.getId());
            iotPickDeviceFaceService.updateIotPickDeviceFace(iotDeviceFace);
        } else {
            iotPickDeviceFaceService.insertIotPickDeviceFace(iotDeviceFace);
        }
    }

    /**
     * 根据不在下发设备内删除人脸
     *
     * @param swapPickFace
     */
    public void deleteByNotDeviceNos(SwapPickFace swapPickFace) {
        IotPickDeviceFace iotDeviceFace = new IotPickDeviceFace();
        iotDeviceFace.setStatus(IotConstants.FACE_STATUS_DELETE);
        iotDeviceFace.setStatusOld(IotConstants.FACE_STATIC_OLD_DEL);
        iotDeviceFace.setNotDeviceNos(swapPickFace.getDownloadDevice());
        iotDeviceFace.setUuid(swapPickFace.getUuid());
        iotPickDeviceFaceService.updateIotPickDeviceFaceByParams(iotDeviceFace);
    }

    /**
     * 根据下发设备内删除人脸
     * @param swapPickFace
     */
    public void deleteByDeviceNos(SwapPickFace swapPickFace) {
        IotPickDeviceFace iotDeviceFace = new IotPickDeviceFace();
        iotDeviceFace.setStatus(IotConstants.FACE_STATUS_DELETE);
        iotDeviceFace.setStatusOld(IotConstants.FACE_STATIC_OLD_DEL);
        iotDeviceFace.setDeviceNos(swapPickFace.getDownloadDevice());
        iotDeviceFace.setUuid(swapPickFace.getUuid());
        iotPickDeviceFaceService.updateIotPickDeviceFaceByParams(iotDeviceFace);
    }
}
